import React from 'react';

export default function withTimeoutSkeleton(WrappedComponent) {
  return class component extends React.Component {
    static defaultProps = {
      delay: 300,
    };

    state = {
      show: false,
    };

    componentDidMount() {
      const { delay } = this.props;
      setTimeout(() => {
        this.setState({
          show: true,
        });
      }, delay);
    }

    render() {
      const { show } = this.state;
      if (!show) {
        return null;
      }

      return <WrappedComponent {...this.props} />;
    }
  };
}
